from sender import sendFrame_xor
from receiver import receive_packet

# 发送一帧
# for i in range(5):
#     print(f"发送帧 {i}")
#     pkts = sendFrame(b'a'*750, loss_rate=0.05, rtt_ms=50, fec_rate=0.3, max_pay_load=1400)
#     # 逐个喂给接收端
#     done_frames = []
#     for raw in pkts:
#         done_frames += receive_packet(raw)

    
# print("完成帧：", done_frames)
done_frames = []
for i in range(10):
    print(f"发送帧 {i}")
    pkts = sendFrame_xor(b'a' * 1800, loss_rate=0.05, rtt_ms=50, fec_rate=0.1, max_pay_load=1400)
    if i %2==0:
        # 模拟丢包
        pkts = pkts[1:]
    for raw in pkts:
        newly, pkt_id = receive_packet(raw)   # 正确解包：newly 是“本次新完成的帧号列表”
        if newly:
            done_frames.extend(newly)         # 只把“新完成的帧号”加入统计
    print(done_frames)

    
print("完成帧：", done_frames)
